/**
 * Created by ljy on 2016/6/23.
 */

define(function(require,exports,module){
    //box3
    var index = 0;
    //自动轮播
    var timer = setInterval(function(){
        index++
        play()
    },2000)

    $(".box3").mouseenter(function(){
        clearInterval(timer)
    })
    $(".box3").mouseleave(function(){
        timer = setInterval(function(){
            index++
            play()
        },2000)
    })
    //小按钮
    $(".pointUl li").click(function(){
        index = $(this).index()
        play()
    })
    //下一张
    $(".nextBut").click(function(){
        ++index
        play()
    })
    //上一张
    $(".preBut").click(function(){
        if(index <= 0){
            index = 4
            $(".conUl")[0].style.marginLeft = -500 * 4 + "px";
        }
        $(".conUl").animate({marginLeft:-500 * --index})
    })
    //ul移动函数封装
    function play() {
        $(".conUl").animate({marginLeft:-500 * index},function(){
            if(index >= 4){
                index = 0
                $(".conUl")[0].style.marginLeft = 0 + "px";
            }else if(index <= 0){
                index = 4
                $(".conUl")[0].style.marginLeft = -500 * 4 + "px";
            }
        })
    }
})

